import java.net.ServerSocket;
import java.net.Socket;

/**
 * @className: server
 * @description: 服务端启动类
 * @author: WangXiaosong
 * @date: 2022/6/8
 **/
public class server {
    public static String host = "127.0.0.1";
    public static Integer port = 9999;

    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(port);//持续监听接口
            System.out.println("启动服务器....端口为:" + port + " wait connect...");
            Socket socket = null;

            while (true) {
                socket = serverSocket.accept();//建立socket连接
                System.out.println("收到客户端连接，客户端:" + socket.getInetAddress().getHostAddress() + "已连接到服务器");

                ServerThread serverThread = new ServerThread(socket);
                serverThread.start();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
